﻿// Fill out your copyright notice in the Description page of Project Settings.


#include "GKConfigEditor/Public/GKConfigEditorStyle.h"
#include "Interfaces/IPluginManager.h"
#include "Styling/SlateStyleRegistry.h"

TSharedPtr<FSlateStyleSet> FGKConfigEditorStyle::StyleInstance = NULL;

void FGKConfigEditorStyle::Initialize()
{
	if (!StyleInstance.IsValid())
	{
		StyleInstance = Create();
		FSlateStyleRegistry::RegisterSlateStyle(*StyleInstance);
	}
}

void FGKConfigEditorStyle::Shutdown()
{
	FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance);
	ensure(StyleInstance);
	StyleInstance.Reset();
}

void FGKConfigEditorStyle::ReloadTextures()
{
	if (FSlateApplication::IsInitialized())
	{
		FSlateApplication::Get().GetRenderer()->ReloadTextureResources();
	}
}

const ISlateStyle& FGKConfigEditorStyle::Get()
{
	return *StyleInstance;
}

FName FGKConfigEditorStyle::GetStyleSetName()
{
	return FName("GKConfigEditorStyle");
}

#define JPG_IMAGE_BRUSH( RelativePath, ... ) FSlateImageBrush( Style->RootToContentDir( RelativePath, TEXT(".jpg") ), __VA_ARGS__ )
#define PNG_IMAGE_BRUSH( RelativePath, ... ) FSlateImageBrush( Style->RootToContentDir( RelativePath, TEXT(".png") ), __VA_ARGS__ )

const FVector2D Icon16x16(16.0f, 16.0f);

TSharedRef<FSlateStyleSet> FGKConfigEditorStyle::Create()
{
	TSharedRef<FSlateStyleSet> Style = MakeShareable(new FSlateStyleSet(GetStyleSetName()));
	Style->SetContentRoot(IPluginManager::Get().FindPlugin("GKConfig")->GetBaseDir() / TEXT("Resources"));
	Style->Set("GKConfigEditor.OpenPluginWindow", new JPG_IMAGE_BRUSH(TEXT("Icon1"), Icon16x16));
	Style->Set("GKConfigEditor.TestPluginWindow", new PNG_IMAGE_BRUSH(TEXT("Icon128"), Icon16x16));
	return Style;
}

#undef JPG_IMAGE_BRUSH
#undef PNG_IMAGE_BRUSH
